<?php

namespace App\Service\Author;

use App\Models\Author\AuthorModel;
use App\Models\Customer\CustomerModel;
use DB;
class AuthorService
{
    public static function addJoinLog(array $data)
    {

        $result = DB::table('lsj_join_author')->insert($data);
        return $result;
    }

    public  static function getAuthor($uid)
    {
        $result = CustomerModel::where(['uid' => $uid, 'is_author' => 1])->first();
        return $result;
    }

    public static function getJoinLog($uid)
    {
        $result = AuthorModel::where('uid',$uid)->first();
        return $result;
    }
	
	/**
     * 作者详情
     * 
     */
    public static function getAuthorDetailPage($uid, $auid)
    {
        $user_result = DB::select("select 
(select count(*) from lsj_follow where uid=?) as follow_num,
(select count(*) from lsj_follow where fuid=?) as fans_num,
(select count(*) from lsj_follow  where lsj_follow.fuid =? and lsj_follow.uid=?) as is_follow,
nickname,headimgurl,? as uid,uid as auid,introduce,is_author
from lsj_user
where uid=?",[$auid,$auid,$auid,$uid,$uid,$auid]);
        return $user_result;
    }

    /**
     * 个人主页
     *
     */
    public static function getMyDetailPage($uid)
    {
        $user_result = DB::select("select 
(select count(*) from lsj_follow where uid=?) as follow_num,
(select count(*) from lsj_follow where fuid=?) as fans_num,
(select count(*) from lsj_friend_circle where uid=?) as circle_num,
nickname,headimgurl,uid,introduce,is_author
from lsj_user 
where uid=?",[$uid,$uid,$uid,$uid]);
        $order_result = DB::select("select status as order_status,count(*) as order_num
from lsj_order 
where uid=?  and status in(0,1,2,3)
group by status",[$uid]);
        $result = array(
            'user' => $user_result,
            'buy_order' => $order_result
        );
        return $result;
    }

    /**
     *  小程序个人主页
     */
    public static function getProgramMyDetailPage($uid)
    {
        $order_result = DB::select("select status as order_status,count(*) as order_num
from lsj_order 
where uid=?  and status in(0,1,2,3)
group by status",[$uid]);

        return $order_result;
    }
}